<article id="wikiArticle">
<div> <div class="blockIndicator nonStandard nonStandardHeader">
<p><strong><span class="icon-only-inline" title="This API has not been standardized."><i class="icon-warning-sign"> </i></span> 非标准</strong><br/>
      该特性是非标准的，请尽量不要在生产环境中使用它！</p>
</div></div>
<p><strong>rightContext </strong>非标准属性是正则表达式的静态和只读属性，含有最新匹配的右侧子串。 <code>RegExp.$'</code> 是这个属性的别名。</p>
<h2 id="语法">语法</h2>
<pre><code class="language-javascript"><code><var>RegExp</var>.rightContext
RegExp["$'"]</code>
</code></pre>
<h2 id="描述">描述</h2>
<p><code>rightContext</code> 属性是静态的，不是正则表达式独立对象的属性。反之，你应始终将其使用为 <code>RegExp.rightContext</code> 或者 <code>RegExp["$'"]</code>。</p>
<p><code>rightContext</code> 属性的值是只读的，并且会在匹配成功时修改。</p>
<p>你不能使用属性访问器(<code>RegExp.$'</code>)来使用简写的别名，因为解析器在这里会将其看做字符串的开始，并抛出 <a href="Reference/Global_Objects/SyntaxError" title="SyntaxError 对象代表尝试解析语法上不合法的代码的错误。"><code>SyntaxError</code></a>。使用 <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors">方括号符号</a>来访问属性。</p>
<h2 id="示例">示例</h2>
<h3 id="使用_rightContext_和_'">使用 <code>rightContext</code> 和 <code>$'</code></h3>
<pre><code  class="language-javascript">var re = /hello/g;
re.test('hello world!');
RegExp.rightContext; // " world!"
RegExp["$'"];       // " world!"
</code></pre>
<h2 id="规范">规范</h2>
<p>非标准。并不是任何现行规范的一部分。</p>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<div><div class="blockIndicator warning"><strong><a class="external" href="https://github.com/mdn/browser-compat-data" rel="noopener">We're converting our compatibility data into a machine-readable JSON format</a></strong>.
            This compatibility table still uses the old format,
            because we haven't yet converted the data it contains.
            <strong><a class="new" href="/zh-CN/docs/MDN/Contribute/Structures/Compatibility_tables" rel="nofollow">Find out how you can help!</a></strong></div>
<div class="htab">
<a id="AutoCompatibilityTable" name="AutoCompatibilityTable"></a>
<ul>
<li class="selected"><a>Desktop</a></li>
<li><a>Mobile</a></li>
</ul>
</div></div>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Chrome</th>
<th>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
</tr>
<tr>
<td>Basic support</td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Android</th>
<th>Chrome for Android</th>
<th>Firefox Mobile (Gecko)</th>
<th>IE Mobile</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>Basic support</td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
</tr>
</tbody>
</table>
</div>
<h2 id="另见">另见</h2>
<ul>
<li><span class="icon-only-inline" title="This API has not been standardized."><i class="icon-warning-sign"> </i></span> <a href="Reference/Global_Objects/RegExp/input" title="input 非标准属性是正则表达式静态属性，含有正则表达式所匹配的字符串。RegExp.$_是这个属性的别名。"><code>RegExp.input ($_)</code></a></li>
<li><span class="icon-only-inline" title="This API has not been standardized."><i class="icon-warning-sign"> </i></span> <a href="Reference/Global_Objects/RegExp/lastMatch" title="lastMatch 非标准属性是正则表达式的静态和只读属性，含有最后匹配到的字符串。RegExp.$&amp; 是这个属性的别名。"><code>RegExp.lastMatch ($&amp;)</code></a></li>
<li><span class="icon-only-inline" title="This API has not been standardized."><i class="icon-warning-sign"> </i></span> <a href="Reference/Global_Objects/RegExp/lastParen" title="lastParen 非标准属性是正则表达式的静态和只读属性，包含匹配到的最后一个子串（如果存在）。RegExp.$+是这一属性的别名。"><code>RegExp.lastParen ($+)</code></a></li>
<li><span class="icon-only-inline" title="This API has not been standardized."><i class="icon-warning-sign"> </i></span> <a href="Reference/Global_Objects/RegExp/leftContext" title="leftContext 非标准属性是正则表达式的静态和只读属性，含有最新匹配的左侧子串。 RegExp.$` 是这个属性的别名。"><code>RegExp.leftContext ($`)</code></a></li>
<li><span class="icon-only-inline" title="This API has not been standardized."><i class="icon-warning-sign"> </i></span> <a href="Reference/Global_Objects/RegExp/n" title="非标准$1, $2, $3, $4, $5, $6, $7, $8, $9 属性是包含括号子串匹配的正则表达式的静态和只读属性。"><code>RegExp.$1-$9</code></a></li>
</ul>
</article>